
package d0325;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class CalendarTest {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的出生年月日：（yyyy-mm-dd）");
        String sDate = sc.nextLine();
        Date bDate = stringToDate(sDate,"yyyy-MM-dd");

        //得到出生时间毫秒值
        long bornDate = bDate.getTime();
        //得到当前日期
        long currentDate = System.currentTimeMillis();

        //计算天数
        long day = (currentDate-bornDate)/1000/60/60/24;
        System.out.println("你来到这个世界："+day+"天了");
    }

    //字符串对象转化成日期
    public static Date stringToDate(String s,String format)
            throws ParseException{
        return new SimpleDateFormat(format).parse(s);
    }
}